package com.github.wxiaoqi.security.crm.core.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.crm.request.MerchantBaseRequest;
import com.github.wxiaoqi.security.common.crm.request.QueryMerchantBaseListRequest;
import com.github.wxiaoqi.security.common.msg.ResponseCode;
import com.github.wxiaoqi.security.common.util.EntityUtils;
import com.github.wxiaoqi.security.crm.core.entity.MerchantBase;
import com.github.wxiaoqi.security.crm.core.mapper.MerchantBaseMapper;

import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 商户客户基础信息
 *
 * @author centerroot
 * @email ${email}
 * @date 2018-07-16 10:15:49
 */
@Slf4j
@Service
public class MerchantBaseBiz extends BaseBiz<MerchantBaseMapper,MerchantBase> {
	
	
	/**
	 * 查询单个商户基础信息详情
	 * @author centerroot
	 * @time 创建时间:2018年7月16日下午6:02:10
	 * @param personalId
	 * @return
	 */
	public Map<String, Object> queryOneByKeys(@ApiParam("商户客户编号") @RequestParam(value = "merchantId", required = true) String merchantId){
		log.info("【查询单个商户基础信息详情】   请求参数：{}",merchantId);
		Map<String, Object> respMap = new HashMap<String, Object>();
		MerchantBase merchantBase = mapper.selectByPrimaryKey(merchantId);
		respMap.put("merchantBase", merchantBase);
        respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("msg", ResponseCode.OK.getMessage());
		log.info("【查询单个商户基础信息详情】   响应参数：{}",respMap);
		return respMap;
	}
	
	/**
	 * 添加商户基础信息
	 * @author centerroot
	 * @time 创建时间:2018年7月16日下午6:02:15
	 * @param MerchantBaseRequest
	 * @return
	 */
	public Map<String, Object> add(MerchantBaseRequest merchantBaseRequest){
		log.info("【添加商户基础信息】   请求参数：{}",EntityUtils.beanToMap(merchantBaseRequest));
		Map<String, Object> respMap = new HashMap<String, Object>();
		MerchantBase merchantBase = new MerchantBase();
		BeanUtils.copyProperties(merchantBaseRequest,merchantBase);
		mapper.insert(merchantBase);
		respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("msg", ResponseCode.OK.getMessage());
		log.info("【添加商户基础信息】   响应参数：{}",respMap);
		return respMap;
	}
	
	/**
	 * 修改商户基础信息
	 * @author centerroot
	 * @time 创建时间:2018年7月16日下午6:02:22
	 * @param MerchantBaseRequest
	 * @return
	 */
	public Map<String, Object> update(MerchantBaseRequest merchantBaseRequest){
		log.info("【修改商户基础信息】   请求参数：{}",EntityUtils.beanToMap(merchantBaseRequest));
		Map<String, Object> respMap = new HashMap<String, Object>();
		MerchantBase merchantBase = new MerchantBase();
		BeanUtils.copyProperties(merchantBaseRequest,merchantBase);
		mapper.updateByPrimaryKey(merchantBase);
		respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("msg", ResponseCode.OK.getMessage());
		log.info("【修改商户基础信息】   响应参数：{}",respMap);
		return respMap;
	}
	
	/**
	 * 删除商户基础信息
	 * @author centerroot
	 * @time 创建时间:2018年7月16日下午6:02:30
	 * @param personalId
	 * @return
	 */
	public Map<String, Object> delete(@ApiParam("商户客户编号") @RequestParam(value = "merchantId", required = true) String merchantId){
		log.info("【删除商户基础信息】   请求参数：{}",merchantId);
		Map<String, Object> respMap = new HashMap<String, Object>();
		int count = mapper.deleteByPrimaryKey(merchantId);
        respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("msg", ResponseCode.OK.getMessage());
		log.info("【删除商户基础信息】   响应参数：{}",respMap);
		return respMap;
	}
	
}